Skip to content

Document remaining const_cast sites as upward mailboxes; add A7 channel proposal#212

Merged
ASDAlexander77 merged 1 commit into
mainfrom
refactor/gencontext-constcast-p2b
Jul 12, 2026
Merged

Document remaining const_cast sites as upward mailboxes; add A7 channel proposal#212
ASDAlexander77 merged 1 commit into
mainfrom
refactor/gencontext-constcast-p2b

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Summary

Closes the mechanical portion of the A6 const_cast<GenContext&> effort and documents what's left. Comments and docs only — no behavior change.

Investigating the final 10 casts (8 in MLIRGen.cpp, 2 in MLIRCodeLogic.h) showed they are all upward mailboxes: they intentionally write into the caller's context so later code observes the value — the class-field-init statement queue (generatedStatements push/drain), synthesized safe-cast aliases (typeAliasMap), the explicit this: T parameter type (mlirGenParameters), the dispose process-once marker (usingVars), and __switchstate arming variable-allocation placement for following statements. Copy-on-override cannot work for these, GenContext& signatures would ripple through the entire statement chain, and — the key finding — their correctness depends on GenContext's value-copy visibility semantics (a write is visible exactly to contexts copied from the mutated object after the write). The original phase-4 guess ("plain parameters") was wrong: those are out-channels too.

  • Each remaining site now carries a greppable NOTE: upward mailbox comment pointing at the doc.
  • A7 in docs/MLIRGen-refactoring-review.md explains the mechanism and proposes a per-channel redesign (pointer-shared channel object for the statement queue, per-function registry for safe-cast aliases, returned values instead of pokes for mlirGenParameters/mlirGenSwitchState), one PR per channel, each needing review before implementation.

Series scorecard for §3: 31 casts → 10, with every eliminated cast either provably semantics-free or a fixed latent leak, and every survivor documented.

Test plan

  • tslang rebuilds cleanly; smoke subset + MLIRGenTests.exe 12/12 (comment-only change)

🤖 Generated with Claude Code

…el proposal

The 10 remaining const_cast<GenContext&> casts all intentionally write
into the caller''s context so later code observes the value (field-init
statement queue, safe-cast aliases, this-parameter type, dispose marker,
switch-state arming). Copy-on-override cannot work for these and
GenContext& would ripple through the whole statement chain; their
correctness depends on value-copy visibility, which A7 in the review
doc now explains, with a per-channel redesign proposal. Each site
carries a greppable "NOTE: upward mailbox" comment.

No code behavior change (comments and docs only).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@ASDAlexander77 ASDAlexander77 merged commit b0fbaee into main Jul 12, 2026
2 checks passed
@ASDAlexander77 ASDAlexander77 deleted the refactor/gencontext-constcast-p2b branch July 12, 2026 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant